import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

        int[] nums = {2, 3, 2};
        Main main = new Main();
        main.rob(nums);
    }

    //按摩师
    public int massage(int[] nums) {
        int n = nums.length;
        if (n == 0) return 0;
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = nums[0];
        for (int i = 1; i < n; i++) {
            f[i] = g[i - 1] + nums[i];
            g[i] = Math.max(f[i - 1], g[i - 1]);
        }
        return Math.max(f[n - 1], g[n - 1]);
    }

    //打家劫舍2
    public int rob(int[] nums) {
        int n = nums.length;
        return Math.max(nums[0]+rob1(nums,2,n-2),rob1(nums,1,n-1));
    }

    private int  rob1(int[] nums, int left, int right) {
        if(left>right)return 0;
        int[] f= new int[nums.length];
        int[] g= new int[nums.length];
        f[left] = nums[left];
        for(int i=left+1;i<=right;i++){
            f[i] = g[i - 1] + nums[i];
            g[i] = Math.max(f[i - 1], g[i - 1]);
        }
        return Math.max(f[right], g[right]);
    }
    //删除并获取点数
    public int deleteAndEarn(int[] nums) {
        // 1. 预处理
        int n = 10001;
         int[] arr = new int[n];
         for(int x : nums) arr[x] += x;

         int[] f= new int[n];
         int[] g = new int[n];
         f[0] = nums[0];
         for(int i=1;i<=n;i++){
             f[i] = g[i-1] + nums[i];
             g[i] = Math.max(f[i-1], g[i-1]);
         }
         return Math.max(f[n], g[n]);
    }
}